var tgd = tgd || {};
tgd.Media = tgd.Media || {};


tgd.Media.Entry = function (args) {

    var db;
    db = openDatabase("MediaLibrary", "1.0", "Maverick Mindless Drones - Media Library", 5 * 1024 * 1024);

    var _upc = (args.UPC ? args.UPC : "");
    var _name = (args.Name ? args.Name : "");
    var _thumbURL = (args.ThumbURL ? args.ThumbURL : "");
    var _thumbSource = (args.ThumbSource ? args.ThumbSource : "");
    var _nameSource = (args.NameSource ? args.NameSource : "");
    var _libraryID = (args.LibraryID ? args.LibraryID : null);
    var _google;

    this.getName = function() {
        return _name;
    }

    this.getThumbURL = function() {
        return _thumbURL;
    }

    this.getNameSource = function() {
        return _nameSource;
    }

    this.getUPC = function() {
        return _upc;
    }
    
    this.getLibraryID = function() {
        return _libraryID;
    }

    this.setLibraryID = function(id) {
        _id = id;
    }

    this.setName = function(name) {
        _name = name;
    }

    this.setThumbURL = function(url) {
        _thumbURL = url;
    }

    this.setNameSource = function(url) {
        _nameSource = url;
    }

    this.getGoogleData = function() {
        return _google;
    }

    this.setGoogleData = function(val) {
        _google = val;
    }

    this.save = function(callback) {
        var self = this;
        db.transaction(
            function(t) {
                t.executeSql("UPDATE entry SET Name = ?, ThumbURL = ?, NameSource = ? WHERE UPC = ?",
                    [_name, _thumbURL, _nameSource, _upc],
                    function(t, results) {
                        callback({ Status : 1, Message : "Entry saved.", Entry : self });
                    },
                    function(t, error) {
                        callback({ Status : 0, Message : error.message, Entry : self });
                    }
                );
            }
        );
    }
}
